package com.slipper.core.file.config;

import com.slipper.core.file.IFileService;
import com.slipper.core.file.minio.MinioFileService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "file.storage.mode", havingValue = "minio")
public class MinioFileServiceConfiguration {
    @Value("${minio.endpoint}")
    private String endpoint;
    @Value("${minio.access-key}")
    private String accessKey;
    @Value("${minio.secret-key}")
    private String secretKey;
    @Value("${minio.bucket-name}")
    private String bucketName;

    @Bean("fileService")
    public IFileService minioFileService() throws Exception {
        return new MinioFileService(this.endpoint, this.accessKey, this.secretKey, this.bucketName);
    }
}
